package com.hkbigdata.source;

import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;

import java.util.Properties;

/**
 * @author liuanbo
 * @creat 2024-04-02-19:46
 * @see 2194550857@qq.com
 */
public class Flink03_Source_Kafka {
    public static void main(String[] args) throws Exception {
        //1.创建kafka配置
        Properties properties = new Properties();
        //1.1 设置机器地址
        properties.setProperty("bootstrap.servers", "hadoop102:9092,hadoop103:9092,hadoop104:9092");
        //1.2消费者组id
        properties.setProperty("group.id", "flink kafka");
        //1.3消费者消费位置
        properties.setProperty("auto.offset.reset","latest");

        //2.创建环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        //3.读取数据
        DataStreamSource<String> stringDataStreamSource = env.addSource(new FlinkKafkaConsumer<String>("test", new SimpleStringSchema(), properties));

        stringDataStreamSource.print();


        env.execute();
    }
}
